package org.gwu.seuss.persistence;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.gwu.seuss.domain.File;

public interface FilesMapper {

	@Select("SELECT * FROM files")
	public List<File> selectAllFiles();

	@Select("SELECT * FROM files WHERE ownerId = #{ownerId} and deleted = false")
	public List<File> selectAllFileByOwner(@Param("ownerId") int ownerId);
	
	@Select("SELECT * FROM files WHERE ownerId = #{ownerId} and filename = #{filename}")
	public File selectFile(@Param("ownerId") int ownerId, @Param("filename") String filename);
	
	@Insert("INSERT INTO files (ownerId, filename, path, mac, salt, iv) VALUES ( #{ownerId}, #{filename}, #{path}, #{mac}, #{salt}, #{iv} )")
	@Options(useGeneratedKeys=true, keyProperty="fileId", keyColumn="fileId")
	public int insertFile(File file);
	
	@Update("UPDATE files SET deleted = true WHERE ownerId = #{ownerId} and filename = #{filename}")
	public int deleteFile(@Param("ownerId") int ownerId, @Param("filename") String filename);	
}